
/*********************************************************************************

  *Copyright(C),??????????????????

  *Author:  ?????

**********************************************************************************/

#include "tiva_sys.h"

/*************************************************************************************************/
extern uint8_t DBG_RxProBuf[100];
extern uint8_t TCK_RxProBuf[100];
extern uint8_t CTL_RxProBuf[100];

uint8_t *pdbgReader=DBG_RxProBuf;
uint8_t *ptckReader=TCK_RxProBuf;
uint8_t *pctlReader=CTL_RxProBuf;

void UART0_IRQHandler(void)
{
	uint32_t flag = UARTIntStatus(UART0_BASE,1);
	UARTIntClear(UART0_BASE,flag);	
	while(UARTCharsAvail(UART0_BASE))
	{			                                                                                                                                                                                                                    
		*pdbgReader = UARTCharGet(UART0_BASE);
		pdbgReader++;
	}
	if(*(pdbgReader-1)==';')
	{
		pdbgReader=DBG_RxProBuf;
		debugUartISR();
	}
}

void Usart0_init(uint32_t bode)
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
	UARTStdioConfig(0, bode, 16000000);
	UARTFIFODisable(UART0_BASE);
	UARTIntEnable(UART0_BASE,UART_INT_RX); 

	UARTIntRegister(UART0_BASE,UART0_IRQHandler); 
	IntPrioritySet(INT_UART0, USER_INT0);
}


void Usart0_txpacket(uint8_t *packet)
{
	uint8_t i=0;
	while(*(packet+i)!=0)
	{
		UARTCharPut(UART0_BASE,*(packet+i));
		i++;
	}
}

/*************************************************************************************************/

void UART1_IRQHandler(void)
{
	uint32_t flag = UARTIntStatus(UART1_BASE,1);
  UARTIntClear(UART1_BASE,flag);	
  while(UARTCharsAvail(UART1_BASE))
  {			                                                                                                                                                                                                                    
		*ptckReader = UARTCharGet(UART1_BASE);
		ptckReader++;
  }
	if(*(ptckReader-1)==';')
	{
		ptckReader=TCK_RxProBuf;
		trackUartISR();
	}
}

void Usart1_init(uint32_t bode)
{
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
  GPIOPinConfigure(GPIO_PB0_U1RX);
  GPIOPinConfigure(GPIO_PB1_U1TX);
  GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	
  UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
  UARTStdioConfig(1, bode, 16000000);
  UARTFIFODisable(UART1_BASE);
  UARTIntEnable(UART1_BASE,UART_INT_RX); 
  UARTIntRegister(UART1_BASE,UART1_IRQHandler); 
  IntPrioritySet(INT_UART1, USER_INT1);
}

void Usart1_txpacket(uint8_t *packet)
{
	uint8_t i=0;
	while(*(packet+i)!=0)
	{
		UARTCharPut(UART1_BASE,*(packet+i));
		i++;
	}
}

/*************************************************************************************************/

void UART5_IRQHandler(void)
{
	uint8_t data_temp;
	uint32_t flag = UARTIntStatus(UART5_BASE,1); 
  UARTIntClear(UART5_BASE,flag); 
  while(UARTCharsAvail(UART5_BASE)) 
  {		                                                                                                                                                                                                                    
		*pctlReader = UARTCharGet(UART5_BASE);
		pctlReader++;
  }
	if(*(pctlReader-1)==';')
	{
		pctlReader=CTL_RxProBuf;
		ctrlUartISR();
	}
}

void Usart5_init(uint32_t bode)
{
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
  GPIOPinConfigure(GPIO_PE4_U5RX);
  GPIOPinConfigure(GPIO_PE5_U5TX);
  GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
	
  UARTClockSourceSet(UART5_BASE, UART_CLOCK_PIOSC);
	UARTConfigSetExpClk(UART5_BASE, 16000000, bode,
                            (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_WLEN_8));
  UARTFIFODisable(UART5_BASE);
  UARTIntEnable(UART5_BASE,UART_INT_RX); 
  UARTIntRegister(UART5_BASE,UART5_IRQHandler); 
  IntPrioritySet(INT_UART5, USER_INT2);
}

void Usart5_txpacket(uint8_t *packet)
{
	uint8_t i=0;
	while(*(packet+i)!=0)
	{
		UARTCharPut(UART5_BASE,*(packet+i));
		i++;
	}
}

/*************************************************************************************************/

void UART_printf(const char *pcString, ...)
{}
